<?php
    use User\Model\LiveModel;
?>
<style>
    .table>tbody>tr>td{vertical-align: middle}
    .table>tbody>tr>td>a{margin-top:5px}
</style>
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">话题</h1>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a style="margin-left:7px" href="/User/Live/editTopic?room_id={$room_id}" class="btn btn-success">新增</a>
                    <a href="javascript:;" id="deleteAll" class="btn btn-danger">删除</a>
                    <form class="input-group" action="/User/Live/topic" style="width: 300px;float:right">
                        <input type="hidden" name="room_id" value="{$room_id}">
                        <input type="text" class="form-control" name="title" placeholder="输入话题名称搜索" value="{$title}">
                        <span class="input-group-btn">
							<button class="btn btn-default" type="submit">
								<i class="fa fa-search"></i>
							</button>
						</span>
                    </form>
                </div>
                <div class="panel-body">
                    <div class="col-lg-12">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" id="selectAll"></th>
                                    <th>编号</th>
                                    <th style="width:180px">话题名称</th>
                                    <th>地址</th>
                                    <th>邀请主播链接</th>
                                    <th>状态</th>
                                    <th style="width:250px">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <volist name="list" id="item">
                                    <tr>
                                        <td><input type="checkbox" name="ids" value="{$item.id}"></td>
                                        <td>{$item.id}</td>
                                        <td style="width:180px">{$item.topic_title}</td>
                                        <td>{$item.link}</td>
                                        <td>{$item.admin_link}</td>
                                        <td>
                                            <if condition="$item.status eq LiveModel::TOPIC_ACTIVE">
                                                <span class="label label-success">发布</span>
                                            <elseif condition="$item.status eq LiveModel::TOPIC_APPLY"/>
                                                <span class="label label-warning">停用</span>
                                            <else/>
                                                <span class="label label-warning">已删除</span>
                                            </if>
                                        </td>
                                        <td style="width:250px">
                                            <a type="button" href="/User/Live/editTopic?id={$item['id']}&room_id={$room_id}" class="btn btn-info">编辑</a>
                                            <a type="button" href="javascript:;" onclick="return statusTopic({$item['id']}, 'active');" class="btn btn-success">发布</a>
                                            <a type="button" href="javascript:;" onclick="return statusTopic({$item['id']}, 'apply');" class="btn btn-warning">停用</a>
                                            <a type="button" href="javascript:;" onclick="return statusTopic({$item['id']}, 'delete');" class="btn btn-danger">删除</a>
                                            <a type="button" href="/User/Live/blacklist?topic_id={$item['id']}" class="btn btn-warning">用户管理</a>
                                            <a type="button" href="/User/Live/comment?topic_id={$item['id']}" class="btn btn-success">评论室管理</a>
                                            <a type="button" href="/User/Live/statistics?topic_id={$item['id']}" class="btn btn-default">数据统计</a>
                                            <a type="button" href="/User/Live/assist?topic_id={$item['id']}" class="btn btn-primary">助理管理</a>
                                            <if condition="$item.topic_type neq LiveModel::TOPIC_TYPE_MSG">
                                                <a type="button" href="javascript:;" class="btn btn-default" onclick="replay({$item['id']})">视频回放</a>
                                                <a type="button" href="javascript:;" class="btn btn-info" onclick="recReplay({$item['id']})">推荐回放</a>
                                            </if>
                                        </td>
                                        <div aria-hidden="true" aria-labelledby="ModalLabel" role="dialog" tabindex="-1" id="video_replay{$item['id']}" class="modal fade">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                                        <h4 class="modal-title">视频回放</h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <div class="form-horizontal">
                                                            <div class="form-group">
                                                                <label class="col-lg-2 col-sm-2 control-label">视频回放</label>
                                                                <div class="col-lg-6">
                                                                    <label class="radio-inline" style="display:inline-block">
                                                                        <input onclick="replayAddress({$item['id']}, 1)" type="radio" name="replay{$item['id']}" <if condition="($item.replay eq LiveModel::REPLAY_FALSE) OR ($item.replay eq null)">checked="checked"</if> value="<?php echo LiveModel::REPLAY_FALSE; ?>">&nbsp;关闭
                                                                    </label>
                                                                    <label class="radio-inline" style="display:inline-block">
                                                                        <input onclick="replayAddress({$item['id']}, 2)" type="radio" name="replay{$item['id']}" <if condition="$item.replay eq LiveModel::REPLAY_TRUE">checked="checked"</if> value="<?php echo LiveModel::REPLAY_TRUE; ?>">&nbsp;开启
                                                                    </label>
                                                                </div>
                                                            </div>
                                                            <div class="form-group replay_address_div{$item['id']}" <if condition="($item.replay eq LiveModel::REPLAY_FALSE) OR ($item.replay eq null)">style="display:none"</if>>
                                                                <label class="col-lg-2 col-sm-2 control-label">回放地址</label>
                                                                <div class="col-lg-8">
                                                                    <input class="form-control" name="replay_address{$item['id']}" title="请输入回放地址" value="{$item['replay_address']}" placeholder="请输入回放地址">
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-info" onclick="hideReplay({$item['id']});">提交</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div aria-hidden="true" aria-labelledby="ModalLabel" role="dialog" tabindex="-1" id="rec_replay{$item['id']}" class="modal fade">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                                        <h4 class="modal-title">推荐回放</h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <div class="form-horizontal">
                                                            <div class="form-group">
                                                                <label class="col-lg-2 col-sm-2 control-label">推荐回放</label>
                                                                <div class="col-lg-6">
                                                                    <label class="radio-inline" style="display:inline-block">
                                                                        <input onclick="recReplayAddress({$item['id']}, 1)" type="radio" name="rec_replay{$item['id']}" <if condition="($item.rec_replay eq LiveModel::REPLAY_FALSE) OR ($item.rec_replay eq null)">checked="checked"</if> value="<?php echo LiveModel::REPLAY_FALSE; ?>">&nbsp;关闭
                                                                    </label>
                                                                    <label class="radio-inline" style="display:inline-block">
                                                                        <input onclick="recReplayAddress({$item['id']}, 2)" type="radio" name="rec_replay{$item['id']}" <if condition="$item.rec_replay eq LiveModel::REPLAY_TRUE">checked="checked"</if> value="<?php echo LiveModel::REPLAY_TRUE; ?>">&nbsp;开启
                                                                    </label>
                                                                </div>
                                                            </div>
                                                            <div class="form-group rec_replay_div{$item['id']}" <if condition="($item.rec_replay eq LiveModel::REPLAY_FALSE) OR ($item.rec_replay eq null)">style="display:none"</if>>
                                                                <label class="col-lg-2 col-sm-2 control-label">回放话题1</label>
                                                                <div class="col-lg-10">
                                                                    <select name="rec_replay_id1" id="rec_replay_id1_{$item['id']}" class="form-control m-bot15">
                                                                        <option value="0">请选择</option>
                                                                        <volist name="replay_list" id="rep">
                                                                            <option value="{$rep['id']}" <if condition="$rep.id eq $item['rec_replay_id'][0]">selected</if>>{$rep['topic_title']}</option>
                                                                        </volist>
                                                                    </select>
                                                                </div>
                                                                <label class="col-lg-2 col-sm-2 control-label">回放话题2</label>
                                                                <div class="col-lg-10">
                                                                    <select name="rec_replay_id2" id="rec_replay_id2_{$item['id']}" class="form-control m-bot15">
                                                                        <option value="0">请选择</option>
                                                                        <volist name="replay_list" id="rep">
                                                                            <option value="{$rep['id']}" <if condition="$rep.id eq $item['rec_replay_id'][1]">selected</if>>{$rep['topic_title']}</option>
                                                                        </volist>
                                                                    </select>
                                                                </div>
                                                                <label class="col-lg-2 col-sm-2 control-label">回放话题3</label>
                                                                <div class="col-lg-10">
                                                                    <select name="rec_replay_id3" id="rec_replay_id3_{$item['id']}" class="form-control m-bot15">
                                                                        <option value="0">请选择</option>
                                                                        <volist name="replay_list" id="rep">
                                                                            <option value="{$rep['id']}" <if condition="$rep.id eq $item['rec_replay_id'][2]">selected</if>>{$rep['topic_title']}</option>
                                                                        </volist>
                                                                    </select>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-info" onclick="hideRecReplay({$item['id']});">提交</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </tr>
                                </volist>
                                </tbody>
                            </table>
                        </div>
                        <div class="pages">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $("#selectAll").click(function(){
        if($(this).prop('checked') == true){
            $("input[name=ids]").prop('checked',true);
        }else{
            $("input[name=ids]").prop('checked',false);
        }
    })

    $("#deleteAll").click(function(){
        if(!confirm('确认删除吗？')) return false;
        var ids = "";
        $("input[name=ids]").each(function() {
            if($(this).prop("checked")){
                ids += $(this).val() + "|";
            }
        });
        if(ids != ''){
            $.ajax({
                data: {ids: ids},
                dataType: 'json',
                url: '/User/Live/deleteTopic',
                type: 'get',
                success: function (res) {
                    alert(res['info']);
                    window.location.reload();
                }
            });
        }else{
            alert('请勾选话题！');
        }
    });

    function statusTopic(id, status){
        if(status == "active"){
            if(!confirm('确认发布吗？')) return false;
        }else if(status == "apply"){
            if(!confirm('确认停用吗？')) return false;
        }else{
            if(!confirm('确认删除吗？')) return false;
        }
        $.ajax({
            data: {id: id, status: status},
            dataType: 'json',
            url: '/User/Live/statusTopic',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
        return false;
    }

    function replay(topic_id){
        $('#video_replay'+topic_id).modal('show');
    }

    function replayAddress(topic_id, isreplay) {
        if(isreplay == 1){
            $('.replay_address_div'+topic_id).hide();
        }else{
            $('.replay_address_div'+topic_id).show();
        }
    }

    function hideReplay(topic_id) {
        var replay = $('input[name=replay'+topic_id+']:checked').val();
        var replay_address = $('input[name=replay_address'+topic_id+']').val();
        $.ajax({
            data: {replay: replay, replay_address: replay_address, topic_id: topic_id},
            dataType: 'json',
            url: '/User/Live/replay',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                $('#video_replay'+topic_id).modal('hide');
                window.location.reload();
            }
        });
    }

    function recReplay(topic_id){
        $('#rec_replay'+topic_id).modal('show');
    }

    function recReplayAddress(topic_id, isreplay) {
        if(isreplay == 1){
            $('.rec_replay_div'+topic_id).hide();
        }else{
            $('.rec_replay_div'+topic_id).show();
        }
    }

    function hideRecReplay(topic_id) {
        var rec_replay = $('input[name=rec_replay'+topic_id+']:checked').val();
        var rec_replay_id1 = $('#rec_replay_id1_'+topic_id+' option:selected').val();
        var rec_replay_id2 = $('#rec_replay_id2_'+topic_id+' option:selected').val();
        var rec_replay_id3 = $('#rec_replay_id3_'+topic_id+' option:selected').val();
        var rec_replay_id = rec_replay_id1+','+rec_replay_id2+','+rec_replay_id3;
        $.ajax({
            data: {rec_replay: rec_replay, rec_replay_id: rec_replay_id, topic_id: topic_id},
            dataType: 'json',
            url: '/User/Live/recReplay',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                $('#rec_replay'+topic_id).modal('hide');
                window.location.reload();
            }
        });
    }
</script>